// src/pages/User/index.tsx （示例部分）

import React from "react";
import { Button, Table } from "antd";
import { useAppSelector } from "@store/hooks";
import { selectUserRoles } from "@store/modules/userSlice";

const UserList: React.FC = () => {
  const roles = useAppSelector(selectUserRoles);

  // 判断当前用户是否具有创建用户权限（假设后端返回 roles 包含 'admin'）
  const canCreate = roles.includes("admin");

  const columns = [
    { title: "用户名", dataIndex: "username" },
    { title: "邮箱", dataIndex: "email" },
    {
      title: "操作",
      render: (text: any, record: any) => (
        <div>
          <Button type="link" onClick={() => editUser(record.id)}>
            编辑
          </Button>
          {roles.includes("admin") && (
            <Button type="link" danger onClick={() => deleteUser(record.id)}>
              删除
            </Button>
          )}
        </div>
      ),
    },
  ];

  return (
    <div>
      {canCreate && (
        <Button
          type="primary"
          style={{ marginBottom: 16 }}
          onClick={() => navigate("/user/create")}
        >
          新增用户
        </Button>
      )}
      <Table columns={columns} dataSource={[]} rowKey="id" />
    </div>
  );
};

export default UserList;
